﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

using LuaInterface;

namespace Codeology.Auctioneer
{

    public class AuctioneerRealm
    {

        private string name;
        private List<AuctioneerFaction> factions;

        internal AuctioneerRealm(string realmName, LuaTable realmTable)
        {
            // Set name
            name = realmName;

            // Create somewhere to put factions
            factions = new List<AuctioneerFaction>();

            // Process realms
            foreach(DictionaryEntry entry in realmTable) {
                // Get faction name
                string faction_name = (string)entry.Key;

                // Convert faction name to faction type
                AuctioneerFactionType faction_type;

                if (faction_name == "Alliance") {
                    faction_type = AuctioneerFactionType.Alliance;
                } else if (faction_name == "Horde") {
                    faction_type = AuctioneerFactionType.Horde;
                } else if (faction_name == "Neutral") {
                    faction_type = AuctioneerFactionType.Neutral;
                } else {
                    faction_type = AuctioneerFactionType.Unknown;
                }

                // Get faction table
                LuaTable faction_table = (LuaTable)entry.Value;

                // Create faction
                AuctioneerFaction faction = new AuctioneerFaction(this,faction_type,faction_table);

                // Add faction to factions list
                //if (faction_type != AuctioneerFactionType.Horde)
                factions.Add(faction);
            }
        }

        #region Methods

        public override string ToString()
        {
            return name;
        }

        #endregion

        #region Properties

        public string Name
        {
            get {
                return name;
            }
        }

        public AuctioneerFaction[] Factions
        {
            get {
                return factions.ToArray();
            }
        }

        #endregion

    }

}
